import Vue from 'vue'
import App from './App'
import {Base} from "./common/Base.js";
import Toast from './wxcomponents/dist/toast/toast';
// 全局注册
Vue.prototype.$base = new Base()
Vue.prototype.$toast = Toast

Vue.config.productionTip = false
Vue.directive("input-limit", {
  bind(el, binding) {
    var wins_0 = /[^\d]/g //整数判断
    var wins_1 = /[^\d^\.]/g //小数判断
    var flag = true;
    var points = 0;
    var lengths = 0
    var remainder = 0
    var no_int = 0
    const target = el instanceof HTMLInputElement ? el : el.querySelector("input");
    target.addEventListener("compositionstart", e => {
      flag = false;
    });
    target.addEventListener("compositionend", e => {
      flag = true;
    });
    target.addEventListener("input", e => {
      setTimeout(function() {
        if (flag) {
          if (binding.value == 0) {
            if (wins_0.test(e.target.value)) {
              e.target.value = e.target.value.substring(0,e.target.value.indexOf('.'));
              e.target.dispatchEvent(new Event("input")) //手动更新v-model值
            }
          }
        }
      }, 0)
    })
  }
})
App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
